#include <iostream>
#include <memory>

using namespace std;

class ShareResouce
{
public:
    ShareResouce( const char* str) {
        m_resouce = make_shared<string> (str);
    }

    ShareResouce( const ShareResouce& resouce) {
        if(this == &resouce) {
            return;
        }
        m_resouce = resouce.m_resouce;
    }

    void read() {
        cout << "read : " << *m_resouce << endl;
        cout << m_resouce.use_count() << endl;
    }

    void write( const char* str) {
        string temp = *m_resouce;
        this->m_resouce = make_shared<string> (temp + str);
    }
private:
    shared_ptr<string> m_resouce;
};

// class TestA
// {
//     weak_ptr<TestA> spa;
//     ~TestA(){cout << "~TestA()" << endl;}
//     void show() {
//         cout << "TestA show()" << endl;
//     }
// };

// class TestB
// {
//     weak_ptr<TestA> spb;
//     ~TestB(){cout << "~TestB()" << endl;}
//     void show() {
//         cout << "TestB show()" << endl;
//     }
// };

int main()
{
    ShareResouce r1("abc");
    r1.read();

    ShareResouce r2(r1);
    r2.read();

    ShareResouce r3(r1);
    r3.write("bcd");
    r3.read();


    // shared_ptr<TestA> sp1 = make_shared<TestA>();
    // shared_ptr<TestB> sp2 = make_shared<TestB>();

    return 0;
}